package com.mf.morefun.widget;

import android.content.Context;
import android.graphics.Bitmap;
import android.support.v4.graphics.drawable.RoundedBitmapDrawable;
import android.support.v4.graphics.drawable.RoundedBitmapDrawableFactory;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.request.target.ImageViewTarget;
import com.zhcx.zhcxlibrary.utils.DeviceUtils;

public class TransformationEarsUtils extends ImageViewTarget<Bitmap> {
    private ImageView target;
    private Context mContext;

    public TransformationEarsUtils(ImageView target, Context mContext) {
        super(target);
        this.target = target;
        this.mContext = mContext;
    }

    @Override
    protected void setResource(Bitmap resource) {
        RoundedBitmapDrawable circularBitmapDrawable =
                RoundedBitmapDrawableFactory.create(mContext.getResources(), resource);
        circularBitmapDrawable.setCircular(true);
        target.setImageBitmap(resource);
        if (null != resource){
            //获取原图的宽高
            int width = resource.getWidth();
            int height = resource.getHeight();
        }

//
//        //获取imageView的宽
//        int imageViewWidth = target.getWidth();
//
//        //计算缩放比例
//        float sy = (float) (imageViewWidth * 0.1) / (float) (width * 0.1);
//
//        //计算图片等比例放大后的高
//        int imageViewHeight = (int) (height * sy);
        ViewGroup.LayoutParams params = target.getLayoutParams();
        if(null != params){
            params.height = DeviceUtils.dip2px(mContext, 160);
            params.width = DeviceUtils.dip2px(mContext, 160);
        }else {
            params = new ViewGroup.LayoutParams(DeviceUtils.dip2px(mContext, 160), DeviceUtils.dip2px(mContext, 160));
        }
        target.setLayoutParams(params);
    }
}
